﻿<Window x:Class="Pingy.Main"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ns="clr-namespace:Pingy"
        xmlns:validate="clr-namespace:Pingy.Validators"
    Title="Pingy" Closing="Window_Closing" Width="750" Height="700"
    Background="#FFF3F7FA" WindowStartupLocation="CenterScreen">
    <Window.Resources>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="FontSize" Value="11"/>
            <Setter Property="FontFamily" Value="Tahoma"/>
            <Setter Property="Foreground" Value="#FF4E4E4E"/>
        </Style>

    </Window.Resources>
    <Grid x:Name="LayoutRoot" SnapsToDevicePixels="True">
        <!--<Rectangle Fill="#FFF3F7FA" RadiusX="8" RadiusY="8" StrokeThickness="2" Stroke="#FFA5CCE3" Grid.RowSpan="6"/>-->

        <Grid Margin="10" VerticalAlignment="Stretch">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="2*"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Grid Margin="5">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>


                <TextBlock Text="Search string:"
                               VerticalAlignment="Center"/>
				
				<TextBox VerticalAlignment="Center" Margin="5,5,0,5" Grid.Column="1" Grid.ColumnSpan="3">
                    <TextBox.Text>
                        <Binding Path="SearchString" UpdateSourceTrigger="PropertyChanged">
                        </Binding>
                    </TextBox.Text>
                </TextBox>


                <TextBlock Text="Ping timeout (ms):" Grid.Row="1" VerticalAlignment="Center"/>

                <TextBox x:Name="pingTimeout" TextAlignment="Left" Width="70" Margin="5"
                         Grid.Row="1" Grid.Column="1" 
                         HorizontalAlignment="Left" VerticalAlignment="Center" 
                     ToolTip="When pinging computers outside the LAN, it can be useful to increase the ping time to avoid timeouts.">
                    <TextBox.Text>
                        <Binding Path="Timeout" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
                            <Binding.ValidationRules>
                                <validate:NumberValidator/>
                            </Binding.ValidationRules>
                        </Binding>
                    </TextBox.Text>
                </TextBox>

                <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="2" Margin="10,0,0,0">
                    <TextBlock Text="Repeat:" VerticalAlignment="Center"/>
                    <ComboBox ItemsSource="{Binding Path=RepeatIntervals}" 
                              SelectedValue="{Binding Path=SelectedRepeatInterval, Mode=TwoWay}"
                              DisplayMemberPath="Key"
                              SelectedValuePath="Value"
                              VerticalAlignment="Center" MinWidth="75" Margin="5,0"/>
                </StackPanel>

                <CheckBox IsChecked="{Binding Path=FetchHostInfo, Mode=TwoWay}" Content="Fetch host info" 
                          HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="1" Grid.Column="3"/>

            </Grid>

            <StackPanel Grid.Row="2" Margin="5, 10">
                <TextBlock TextWrapping="Wrap">
                        Tip: Use dash (-) to specify a range, and wildcard (*) to search an entire submask. Separate searches with comma (,).
                </TextBlock>
                <TextBlock Margin="15,5,0,0"> - Example: <Italic>"192.168.0-2.*, 192.168.5.0-10"</Italic></TextBlock>
            </StackPanel>

            <DockPanel Grid.Row="5" Grid.RowSpan="2" Margin="5,10,5,5">
                <DockPanel.Resources>
                    <DataTemplate x:Key="DataGridTextBlockColumn">
                        <TextBlock Text="{Binding}"/>
                    </DataTemplate>
                    <Style TargetType="DataGridCell">
                        <Setter Property="BorderThickness" Value="0"/>
                        <Setter Property="Margin" Value="0"/>
                    </Style>
                </DockPanel.Resources>

                <TextBlock Text="Replies:" DockPanel.Dock="Top"/>

                <DataGrid ItemsSource="{Binding Replies}" Background="White" 
                          IsReadOnly="True"
                          CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" 
                          SelectionUnit="FullRow"
                          AutoGenerateColumns="False" 
                          HorizontalGridLinesBrush="Transparent" VerticalGridLinesBrush="Transparent">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Address" Binding="{Binding Path=Address}" CanUserSort="True" IsReadOnly="False" Width="125"/>
                        <DataGridTextColumn Header="Reply" Binding="{Binding Path=Reply.RoundtripTime}" CanUserSort="True" IsReadOnly="False" Width="75"/>
                        <DataGridTextColumn Header="Host name" Binding="{Binding Path=HostInfo}" CanUserSort="True" IsReadOnly="False" Width="*"/>
                        <DataGridTemplateColumn Header="WHOIS" IsReadOnly="False" Width="50">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Button x:Name="whoBtn" Command="{Binding DataContext.WhoIsCommand, ElementName=LayoutRoot}" CommandParameter="{Binding .}" Padding="0" HorizontalAlignment="Center" 
                                                Background="Transparent" BorderThickness="0">
                                        <Path Height="14" Stretch="Uniform" Fill="Gray" Data="F1 M 15.6001,5.22C 17.3822,5.2515 18.82,5.87949 19.9133,7.104C 21.0067,8.32849 21.5689,9.96048 21.6,12C 21.5923,14.7711 20.4267,16.468 18.1031,17.0906L 18.1031,19.2L 13.1146,19.2L 13.1146,14.3069C 13.4637,14.3485 13.7175,14.3652 13.8762,14.3569C 15.7127,14.5413 16.6373,13.7557 16.65,12C 16.6584,10.3585 16.2917,9.5585 15.55,9.59998C 14.7667,9.59198 14.3834,10.392 14.4,12L 9.45001,12C 9.47205,7.54944 11.5221,5.28946 15.6001,5.22 Z M 15.6501,21.06C 16.4651,21.0844 17.1408,21.3759 17.6773,21.9342C 18.2138,22.4926 18.4919,23.1713 18.5118,23.9701C 18.492,24.769 18.2138,25.4475 17.6773,26.0059C 17.1408,26.5641 16.4651,26.8555 15.6501,26.88C 14.813,26.8555 14.1151,26.5641 13.5565,26.0059C 12.9979,25.4475 12.7079,24.769 12.6863,23.9701C 12.7079,23.1507 12.9979,22.4662 13.5565,21.9167C 14.1151,21.3671 14.813,21.0815 15.6501,21.06 Z M 15.6501,0C 11.2097,0.105347 7.51904,1.64291 4.57797,4.61276C 1.6369,7.58261 0.110931,11.3527 0,15.9231C 0.110931,20.2214 1.6369,23.8045 4.57797,26.6724C 7.51904,29.5402 11.2097,31.0294 15.6501,31.14C 19.9496,31.0294 23.5613,29.5402 26.4853,26.6724C 29.4093,23.8045 30.9309,20.2214 31.05,15.9231C 30.9309,11.3527 29.4093,7.58264 26.4853,4.61276C 23.5613,1.64291 19.9496,0.105347 15.6501,0 Z "/>
                                        <Button.Style>
                                            <Style TargetType="Button">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding HasReply}" Value="False">
                                                        <Setter Property="Visibility" Value="Hidden"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Button.Style>
                                    </Button>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>

                    </DataGrid.Columns>
                </DataGrid>
                <!--<ListView x:Name="replyList" ScrollViewer.VerticalScrollBarVisibility="Auto">
                    <ListView.ItemContainerStyle>
                        <Style TargetType="ListViewItem">
                            <Setter Property="FontSize" Value="11"/>
                            <Setter Property="FontFamily" Value="Tahoma"/>
                            <Setter Property="Foreground" Value="#FF4E4E4E"/>
                            <Setter Property="Margin" Value="2"/>
                            <EventSetter Event="MouseDoubleClick" Handler="ListBoxItem_MouseDoubleClick"/>
                        </Style>
                    </ListView.ItemContainerStyle>
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="Host" DisplayMemberBinding="{Binding Path=Address}" Width="125"/>
                            <GridViewColumn Header="Reply" DisplayMemberBinding="{Binding Path=Reply.RoundtripTime}" Width="75"/>
                            <GridViewColumn Header="Host" DisplayMemberBinding="{Binding Path=HostInfo.HostName}" Width="400"/>
                            <GridViewColumn Header="WHOIS" Width="50">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button x:Name="whoBtn" Command="{Binding DataContext.WhoIsCommand, ElementName=LayoutRoot}" CommandParameter="{Binding .}" Padding="0" HorizontalAlignment="Center" 
                                                Background="Transparent" BorderThickness="0">
                                            <Path Height="14" Stretch="Uniform" Fill="Gray" Data="F1 M 15.6001,5.22C 17.3822,5.2515 18.82,5.87949 19.9133,7.104C 21.0067,8.32849 21.5689,9.96048 21.6,12C 21.5923,14.7711 20.4267,16.468 18.1031,17.0906L 18.1031,19.2L 13.1146,19.2L 13.1146,14.3069C 13.4637,14.3485 13.7175,14.3652 13.8762,14.3569C 15.7127,14.5413 16.6373,13.7557 16.65,12C 16.6584,10.3585 16.2917,9.5585 15.55,9.59998C 14.7667,9.59198 14.3834,10.392 14.4,12L 9.45001,12C 9.47205,7.54944 11.5221,5.28946 15.6001,5.22 Z M 15.6501,21.06C 16.4651,21.0844 17.1408,21.3759 17.6773,21.9342C 18.2138,22.4926 18.4919,23.1713 18.5118,23.9701C 18.492,24.769 18.2138,25.4475 17.6773,26.0059C 17.1408,26.5641 16.4651,26.8555 15.6501,26.88C 14.813,26.8555 14.1151,26.5641 13.5565,26.0059C 12.9979,25.4475 12.7079,24.769 12.6863,23.9701C 12.7079,23.1507 12.9979,22.4662 13.5565,21.9167C 14.1151,21.3671 14.813,21.0815 15.6501,21.06 Z M 15.6501,0C 11.2097,0.105347 7.51904,1.64291 4.57797,4.61276C 1.6369,7.58261 0.110931,11.3527 0,15.9231C 0.110931,20.2214 1.6369,23.8045 4.57797,26.6724C 7.51904,29.5402 11.2097,31.0294 15.6501,31.14C 19.9496,31.0294 23.5613,29.5402 26.4853,26.6724C 29.4093,23.8045 30.9309,20.2214 31.05,15.9231C 30.9309,11.3527 29.4093,7.58264 26.4853,4.61276C 23.5613,1.64291 19.9496,0.105347 15.6501,0 Z "/>
                                            <Button.Style>
                                                <Style TargetType="Button">
                                                    <Style.Triggers>
                                                        <DataTrigger Binding="{Binding HasReply}" Value="False">
                                                            <Setter Property="Visibility" Value="Hidden"/>
                                                        </DataTrigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </Button.Style>
                                        </Button>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>-->
            </DockPanel>

            <Grid Grid.Row="7" Margin="5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Button x:Name="startBtn" Content="Start" Width="60" IsDefault="True" HorizontalAlignment="Left" Click="startBtn_Click"/>
                <StackPanel Grid.Column="1" VerticalAlignment="Center" Orientation="Horizontal" Margin="5">
                    <TextBlock Text="Status: " FontWeight="Bold"/>
                    <TextBlock Text="{Binding Path=GlobalStatus}"/>
                </StackPanel>
                <TextBlock x:Name="durationTxt" Grid.Row="7" Text="00:00" Grid.Column="2" HorizontalAlignment="Right" Margin="5"/>
            </Grid>

            <Grid Grid.Row="8">
                <StackPanel Orientation="Horizontal" Margin="5">

                </StackPanel>
                <!--<Button x:Name="whoisBtn" Content="WHOIS" Margin="5" Width="60" HorizontalAlignment="Left" Click="whoisBtn_Click"/>-->
                <!--<Button Grid.Row="5" x:Name="exitBtn" Content="Exit" Margin="5" Width="70" Padding="2" HorizontalAlignment="Right" Click="exitBtn_Click"/>-->
            </Grid>
        </Grid>
    </Grid>
</Window>

